﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Lamex.Library;
using Lamex.Interface;
using System.IO.Ports;
using System.IO;
using System.Runtime.InteropServices;

namespace Lamex.mNC.UI
{
    public partial class frmNC_PN_AL_Scan_for_Processing : frmBaseChild
    {
        [DllImport("user32.dll")]
        public static extern int MessageBoxTimeoutA(IntPtr hWnd, string msg, string Caps, int type, int Id, int time);//引用DLL

        Lamex.mNC.ucControls.ucShowPic ucShowPicList = null;
        int PL_Count = 0;
        int PL_TempCount = 0;
        int YL_TempCount = 0;
        private static string path_Panel = @"\\tx-fs10\TX-FS1\LAMEX\NC\Porgram\Panel\Aluminum\";
        public frmNC_PN_AL_Scan_for_Processing()
        {
            InitializeComponent();
        }

        private void frmNC_PN_AL_Scan_for_Processing_Load(object sender, EventArgs e)
        {
            try { base.InitButtons(); } catch { }//初始化标准功能，因要应用于RibbonForm，所以加入异常处理
            txtMachineNo.Text = Lamex.Common.Loginer.CurrentUser.Account;
            txtUser.Text = Lamex.Common.Loginer.CurrentUser.AccountName;
            HideQRCodeControl();
            InitCom();//开启COM扫码
                      //特殊用户专用回车功能
            if (Lamex.Common.Loginer.CurrentUser.Account == "TY Chan" || Lamex.Common.Loginer.CurrentUser.Account == "Rocky He" || Lamex.Common.Loginer.CurrentUser.Account == "TX01007" || Lamex.Common.Loginer.CurrentUser.Account == "TX02869" || Lamex.Common.Loginer.CurrentUser.Account == "TX00167")
            {
                txtOrderNumber.ReadOnly = false;
                txtOrderNumber.Text = "PL2007070027_3033262370";
            }
        }

        public override void DoView(IButtonInfo sender)
        {         
            base.DoView(sender);
        }
        //显示图片
        public void ShowPic(string DWGNO, string PARTNO)
        {
            List<string> listPic = new List<string>();
            listPic = Common.GetShowPic.ShowPic_STD(DWGNO, PARTNO);
            ucShowPicList = new ucControls.ucShowPic();
            PicControl.Invoke(new Action(() => { PicControl.Controls.Clear(); }));
            if (listPic.Count > 0)
            {
                // ucShowPicList = new ucControls.ucShowPic();
                ucShowPicList.LoadImageList(listPic);
                ucShowPicList.Dock = DockStyle.Fill;
                // PicControl.Invoke(new Action(() => { PicControl.Controls.Add(ucShowPicList); }));
            }
            PicControl.Invoke(new Action(() => { PicControl.Controls.Add(ucShowPicList); }));
        }
        //判断转码程序是否存在
        public bool IsExistNCProgram(string _Code128)
        {
            bool flag = false;
            DirectoryInfo root_Panel = new DirectoryInfo(path_Panel);
            foreach (FileInfo f in root_Panel.GetFiles("*.NC"))
            {
                if (f.Name.Contains(_Code128))
                {
                    flag = true;
                    break;
                }
                
            }
                return flag;
        }
        #region 获取订单信息
        public void GetOrderInfo(string _Code)
        {
            if (_Code.Length <= 0) return;
            string[] list = _Code.Split('_');
            if (list.Length < 2) return;
            string strORDERNO = list[0];
            string strPARTNO = list[1];
            string strDWGNO = "";
            int OrderQty = 0;
            int BATCH_QTY = 0, BATCH_COUNT = 0, WAIT_QTY = 0;
            txtOrderNo.Invoke(new Action(() => { txtOrderNo.Text = strORDERNO; }));
            txtOrderNumber.Invoke(new Action(() => { txtOrderNumber.Text = strORDERNO; }));
            txtPartNo.Invoke(new Action(() => { txtPartNo.Text = strPARTNO; }));
            Calculate.Cal_BatchQtyHelper.GetDwgAndQty(strPARTNO, strORDERNO, out strDWGNO, out OrderQty);
            txtDwgNo.Invoke(new Action(() => { txtDwgNo.Text = strDWGNO; }));
            txtOrderQty.Invoke(new Action(() => { txtOrderQty.Text = OrderQty.ToString(); }));
            Calculate.Cal_BatchQtyHelper.Get_BatchQty(strORDERNO, strDWGNO, strPARTNO, OrderQty, out BATCH_QTY, out WAIT_QTY, out BATCH_COUNT);
            txtBatchQty.Invoke(new Action(() => { txtBatchQty.Text = BATCH_QTY.ToString(); }));
            txtBatchCount.Invoke(new Action(() => { txtBatchCount.Text = BATCH_COUNT.ToString(); }));
            txtWaitQty.Invoke(new Action(() => { txtWaitQty.Text = WAIT_QTY.ToString(); }));
            PL_Count = BATCH_COUNT;
            //显示二维码
            ShowQRCode(OrderQty, BATCH_QTY, WAIT_QTY, _Code, PL_TempCount);
            //临时放显示图纸号
            ShowPic(strDWGNO, strPARTNO);
        }
        #endregion

        #region 获取当前加工信息
        public void GetProcessInfo(string _QRCode)
        {
            try
            {
                //加工模式
                string ProcessType = Common.GetScanNCType.GetProcessType(_QRCode);
                //加工数量
                int ProcessQty = 0;

                txtProcessType.Invoke(new Action(() =>
                {
                    txtProcessType.Text = ProcessType;
                }));
                //保存二维码扫码记录
                if (ProcessType.Contains("余量"))
                {
                    ProcessQty = Convert.ToInt32(txtWaitQty.Text.Trim().Length <= 0 ? "0" : txtWaitQty.Text.Trim());
                }
                else
                {
                    ProcessQty = Convert.ToInt32(txtBatchQty.Text.Trim().Length <= 0 ? "0" : txtBatchQty.Text.Trim());
                }
                Common.SQLHelper.Insert_Record(_QRCode, txtMachineNo.Text.Trim(), ProcessQty);
                //计算待加工数量
                txtWaitProcessQty.Invoke(new Action(() =>
                {
                    txtWaitProcessQty.Text = Common.SQLHelper.GetScanQty(txtOrderNumber.Text.Trim() + "_" + txtPartNo.Text.Trim(), Convert.ToInt32(txtOrderQty.Text.Trim())).ToString();
                }));

            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(ex.Message);
            }
        }
        #endregion

        #region 获取当天产量
        public void GetOutPutInfo()
        {
            //累计欠货
            txtTotal_NotFinish.Invoke(new Action(() =>
            {
                txtTotal_NotFinish.Text = Calculate.Cal_TotalOutPut.GetNoFinishQty(txtOrderNumber.Text.Trim() + "_" + txtPartNo.Text.Trim()).ToString();
            }));
            //今日完成数量
            DataTable dataTable = Common.GetDataTable.Get_TotalToday();
            txtOutPutToday.Invoke(new Action(() =>
            {
                txtOutPutToday.Text = dataTable.Rows[0][0].ToString();
            }));
            //今日完成工时
            txtWorkHourToday.Invoke(new Action(() =>
            {
                txtWorkHourToday.Text = Calculate.Cal_TotalOutPut.GetTotalWorkHours();
            }));
        }
        #endregion

        #region 判断文件是否传送到机器
        public void SendResult(string QRCode)
        {
            // WinAPI 直接调用  2秒后自动关闭 父窗口句柄没有直接用0代替
            MessageBoxTimeoutA((IntPtr)0, "后台程序正在发送......                                        ", "消息框", 0, 0, 3000);
            if (Common.GetDataTable.GetBarCode(QRCode).Rows.Count <= 0)
                MessageBoxTimeoutA((IntPtr)0, "程序已发送，请按启动键！                                        ", "消息框", 0, 0, 3000);
            else
            {
                MessageBoxTimeoutA((IntPtr)0, "程序未发送，正在检查中......                                        ", "消息框", 0, 0, 3000);
                if (Common.GetDataTable.GetBarCode(QRCode).Rows.Count <= 0)
                    MessageBoxTimeoutA((IntPtr)0, "程序已发送，请按启动键！                                        ", "消息框", 0, 0, 3000);
                else
                    // MessageBoxTimeoutA((IntPtr)0, "程序发送失败，请检查服务器！                                        ", "消息框", 0, 0, 3000);
                    XtraMessageBox.Show("程序发送失败，请检查服务器！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        #endregion

        #region 生成/显示二维码
        /// <summary>
        /// 生成二维码
        /// </summary>
        /// <param name="OrderQty">订单数量</param>
        /// <param name="BatchQty">批量数量</param>
        /// <param name="WaitQty">余量数量</param>
        /// <param name="OrderNumber">订单号</param>
        /// <param name="Count">批量累计次数</param>
        public void ShowQRCode(int OrderQty, int BatchQty, int WaitQty, string OrderNumber, int Count)
        {
            if (OrderQty <= 0) return;
            //生成余量二维码
            if (WaitQty == 0 || YL_TempCount > 1)
            {
                barCode_ZWS_L.Invoke(new Action(() =>
                {
                    barCode_ZWS_L.Visible = false;
                }));
                barCode_ZWS_R.Invoke(new Action(() =>
                {
                    barCode_ZWS_R.Visible = false;
                }));
            }
            else
            {
                barCode_ZWS_L.Invoke(new Action(() =>
                {
                    barCode_ZWS_L.Visible = true;
                    barCode_ZWS_L.Text = OrderNumber + "_ZWS_L_" + YL_TempCount.ToString().PadLeft(3, '0');
                    // barCode_ZWS_L.Text = OrderNumber + "_ZWS_L_001";
                }));
                barCode_ZWS_R.Invoke(new Action(() =>
                {
                    barCode_ZWS_R.Visible = true;
                    barCode_ZWS_R.Text = OrderNumber + "_ZWS_R_" + YL_TempCount.ToString().PadLeft(3, '0');
                    // barCode_ZWS_R.Text = OrderNumber + "_ZWS_R_001";
                }));
                // ChangeQRCode(OrderNumber, Count);
            }
            //生成批量二维码
            if (OrderQty < BatchQty)
            {
                barCode_ZPL_L.Invoke(new Action(() =>
                {
                    barCode_ZPL_L.Visible = false;
                }));
                barCode_ZPL_R.Invoke(new Action(() =>
                {
                    barCode_ZPL_R.Visible = false;
                }));
            }
            else
            {
                barCode_ZPL_L.Invoke(new Action(() =>
                {
                    barCode_ZPL_L.Visible = true;
                }));
                barCode_ZPL_R.Invoke(new Action(() =>
                {
                    barCode_ZPL_R.Visible = true;
                }));
                ChangeQRCode("",OrderNumber, Count);
            }
        }
        public void ShowNotQRCode()
        {
            barCode_ZWS_L.Invoke(new Action(() =>
            {
                barCode_ZWS_L.Visible = false;
            }));
            barCode_ZWS_R.Invoke(new Action(() =>
            {
                barCode_ZWS_R.Visible = false;
            }));
        }
        #endregion

        #region 二维码变化
        public void ChangeQRCode(string ORCode,string OrderNumber, int Count)
        {
            //当二维码是余量扫描时，扫描后二维码立即消失
            if (ORCode.Contains("ZWS"))
            {
                barCode_ZWS_L.Invoke(new Action(() =>
                {
                    barCode_ZWS_L.Visible = false;
                }));
                barCode_ZWS_R.Invoke(new Action(() =>
                {
                    barCode_ZWS_R.Visible = false;
                }));
            }
            //当二维码是批量扫描时最后一个二维码应消失
            if (Count > PL_Count)
            {
                barCode_ZPL_L.Invoke(new Action(() =>
                {
                    barCode_ZPL_L.Visible = false;
                }));
                barCode_ZPL_R.Invoke(new Action(() =>
                {
                    barCode_ZPL_R.Visible = false;
                }));
                return;
            }
         

            //颜色变化
            ChangeQRCodeColor(Count);
            //改变二维码内容
            barCode_ZPL_L.Invoke(new Action(() =>
            {
                barCode_ZPL_L.Text = OrderNumber + "_ZPL_L_" + Count.ToString().PadLeft(3, '0');
            }));
            barCode_ZPL_R.Invoke(new Action(() =>
            {
                barCode_ZPL_R.Text = OrderNumber + "_ZPL_R_" + Count.ToString().PadLeft(3, '0');
            }));

        }
        public void ChangeQRCodeColor(int Count)
        {
            //奇数黑色
            if (Convert.ToBoolean(Count % 2))
            {
                barCode_ZPL_L.Invoke(new Action(() =>
                {
                    barCode_ZPL_L.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(32)))), ((int)(((byte)(31)))), ((int)(((byte)(53)))));
                }));
                barCode_ZPL_R.Invoke(new Action(() =>
                {
                    barCode_ZPL_R.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(32)))), ((int)(((byte)(31)))), ((int)(((byte)(53)))));
                }));
            }
            //偶数红色
            else
            {
                barCode_ZPL_L.Invoke(new Action(() =>
                {
                    barCode_ZPL_L.ForeColor = System.Drawing.Color.Red;
                }));
                barCode_ZPL_R.Invoke(new Action(() =>
                {
                    barCode_ZPL_R.ForeColor = System.Drawing.Color.Red;
                }));
            }
        }
        #endregion
        public void HideQRCodeControl()
        {
            //sOrderNo.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
            barCode_ZPL_L.Visible = false;
            barCode_ZPL_R.Visible = false;
            barCode_ZWS_L.Visible = false;
            barCode_ZWS_R.Visible = false;

        }
        #region 扫描COM实现
        SerialPort serialPort1 = new SerialPort();
        SerialPort serialPort2 = new SerialPort();
        SerialPort serialPort3 = new SerialPort();
        SerialPort serialPort4 = new SerialPort();
        SerialPort serialPort5 = new SerialPort();
        SerialPort serialPort6 = new SerialPort();
        SerialPort serialPort7 = new SerialPort();
        SerialPort serialPort8 = new SerialPort();
        string COM1 = "";
        string COM2 = "";
        string COM3 = "";
        string COM4 = "";
        string COM5 = "";
        string COM6 = "";
        string COM7 = "";
        string COM8 = "";

        public void InitCom()
        {
            string[] str = SerialPort.GetPortNames();
            if (str == null)
            {
                return;
            }
            Lamex.Common.IniFile ini = new Lamex.Common.IniFile(Application.StartupPath + "\\config\\ComSetting.ini");
            COM1 = ini.IniReadValue("COM Configuration", "COM1");
            COM2 = ini.IniReadValue("COM Configuration", "COM2");
            COM3 = ini.IniReadValue("COM Configuration", "COM3");
            COM4 = ini.IniReadValue("COM Configuration", "COM4");
            COM5 = ini.IniReadValue("COM Configuration", "COM5");
            COM6 = ini.IniReadValue("COM Configuration", "COM6");
            COM7 = ini.IniReadValue("COM Configuration", "COM7");
            COM8 = ini.IniReadValue("COM Configuration", "COM8");
            //添加串口项目
            foreach (string s in System.IO.Ports.SerialPort.GetPortNames())
            {
                //获取有多少个COM口
                if (s == COM1)
                {
                    serialPort1 = new SerialPort();
                    InstanceSerialPort(s, serialPort1);
                }
                else if (s == COM2)
                {
                    serialPort2 = new SerialPort();
                    InstanceSerialPort(s, serialPort2);
                }
                else if (s == COM3)
                {
                    serialPort3 = new SerialPort();
                    InstanceSerialPort(s, serialPort3);
                }
                else if (s == COM4)
                {
                    serialPort4 = new SerialPort();
                    InstanceSerialPort(s, serialPort4);
                }
                else if (s == COM5)
                {
                    serialPort5 = new SerialPort();
                    InstanceSerialPort(s, serialPort5);
                }
                else if (s == COM6)
                {
                    serialPort6 = new SerialPort();
                    InstanceSerialPort(s, serialPort6);
                }
                else if (s == COM7)
                {
                    serialPort7 = new SerialPort();
                    InstanceSerialPort(s, serialPort7);
                }
                else if (s == COM8)
                {
                    serialPort8 = new SerialPort();
                    InstanceSerialPort(s, serialPort8);
                }

            }
            //StartTime();
            //alterTime();
        }

        public void InitSingleCom(string PortName)
        {
            string[] str = SerialPort.GetPortNames();

            //添加串口项目
            foreach (string s in System.IO.Ports.SerialPort.GetPortNames())
            {
                //获取有多少个COM口
                if (s == PortName)
                {
                    serialPort1 = new SerialPort();
                    InstanceSerialPort(PortName, serialPort1);
                }
                else if (s == PortName)
                {
                    serialPort2 = new SerialPort();
                    InstanceSerialPort(PortName, serialPort2);
                }
                else if (s == PortName)
                {
                    serialPort3 = new SerialPort();
                    InstanceSerialPort(PortName, serialPort3);
                }
                else if (s == PortName)
                {
                    serialPort4 = new SerialPort();
                    InstanceSerialPort(PortName, serialPort4);
                }
                else if (s == PortName)
                {
                    serialPort5 = new SerialPort();
                    InstanceSerialPort(PortName, serialPort5);
                }
                else if (s == PortName)
                {
                    serialPort6 = new SerialPort();
                    InstanceSerialPort(PortName, serialPort6);
                }
                else if (s == PortName)
                {
                    serialPort7 = new SerialPort();
                    InstanceSerialPort(PortName, serialPort7);
                }
                else if (s == PortName)
                {
                    serialPort8 = new SerialPort();
                    InstanceSerialPort(PortName, serialPort8);
                }

                System.Threading.Thread.Sleep(1000);

            }
        }
        /// <summary>
        /// 实例化串行端口资源
        /// </summary>
        public void InstanceSerialPort(string comName, SerialPort serialPort)
        {
            try
            {
                //实例化串行端口
                //SerialPort serialPort = new SerialPort();
                //端口名  注:因为使用的是USB转RS232 所以去设备管理器中查看一下虚拟com口的名字
                serialPort.PortName = comName;
                //波特率
                serialPort.BaudRate = 9600;
                //奇偶校验
                serialPort.Parity = Parity.None;
                //停止位
                serialPort.StopBits = StopBits.One;
                //数据位
                serialPort.DataBits = 8;
                //忽略null字节
                serialPort.DiscardNull = true;
                //接收事件
                serialPort.DataReceived += serialPort_DataReceived;
                //开启串口
                serialPort.Open();
                //alterTime();
            }
            catch (Exception ex)
            {
                //XtraMessageBox.Show(ex.Message);
            }
        }
        /// <summary>
        /// 接收数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void serialPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            SerialPort serialPort = (SerialPort)sender;
            try
            {
                ReceiveData(serialPort);
            }
            catch (Exception ex)
            {
                //SetMessage(ex.Message, serialPort.PortName);
            }
        }

        public void ReceiveData(object serialPortobj)
        {
            SerialPort serialPort = (SerialPort)serialPortobj;
            try
            {
                //防止数据接收不完整 线程sleep(100)
                System.Threading.Thread.Sleep(100);

                string strBarcode = serialPort.ReadExisting();
                strBarcode = strBarcode.Replace("\r", "");
                if (strBarcode == string.Empty)
                {
                    return;
                }
                else
                {
                    //一维码扫描
                    if (strBarcode.Length <= 26)
                    {
                        if (IsExistNCProgram(strBarcode))
                        {
                            ClearControl();
                            PL_TempCount = Common.GetSerialNumber.GetSerialNo(strBarcode);
                            YL_TempCount = Common.GetSerialNumber.GetSerialNo_YL(strBarcode);
                            //订单信息
                            GetOrderInfo(strBarcode);
                            //计算待加工数量
                            txtWaitProcessQty.Invoke(new Action(() =>
                            {
                                txtWaitProcessQty.Text = Common.SQLHelper.GetScanQty(txtOrderNumber.Text.Trim() + "_" + txtPartNo.Text.Trim(), Convert.ToInt32(txtOrderQty.Text.Trim())).ToString();
                            }));
                            //当待加工数量为0时，不显示余量二维码
                            if (txtWaitProcessQty.Text.Trim() == "0")
                                ShowNotQRCode();
                            //当天产量
                            GetOutPutInfo();
                        }
                        else
                        {
                            DevExpress.XtraEditors.XtraMessageBox.Show("此订单尚未出NC程序，请预转码后再扫描！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                    }
                    //二维码扫描
                    else
                    {
                        if (Common.CheckQRCode.CheckIsExistDB(txtMachineNo.Text.Trim()))
                        {
                            DevExpress.XtraEditors.XtraMessageBox.Show("上次扫码记录未传输，请检查服务器！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                        if (Common.CheckQRCode.CheckIsOverTime(txtMachineNo.Text.Trim()))
                        {
                            DevExpress.XtraEditors.XtraMessageBox.Show("不能频繁扫码，加工间隔需大于30秒！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                        GetProcessInfo(strBarcode);
                        if (strBarcode.Contains("ZPL"))
                            PL_TempCount++;
                        ChangeQRCode(strBarcode, txtOrderNumber.Text.Trim() + "_" + txtPartNo.Text.Trim(), PL_TempCount);
                        GetOutPutInfo();
                        SendResult(strBarcode);
                    }
                }
            }
            catch (Exception ex)
            {
                //SetMessage(ex.Message, serialPort.PortName);
            }
        }
        public void Timer_TimesUp(object sender, System.Timers.ElapsedEventArgs e)
        {
            if (COM1 == serialPort1.PortName)
            {
                if (serialPort1.IsOpen != true)
                {
                    serialPort1.Close();
                    InitSingleCom(serialPort1.PortName);
                }
            }
            if (COM2 == serialPort2.PortName)
            {
                if (serialPort2.IsOpen != true)
                {
                    serialPort2.Close();
                    InitSingleCom(serialPort2.PortName);
                }
            }
            if (COM3 == serialPort3.PortName)
            {
                if (serialPort3.IsOpen != true)
                {
                    serialPort3.Close();
                    InitSingleCom(serialPort3.PortName);
                }
            }
            if (COM4 == serialPort4.PortName)
            {
                if (serialPort4.IsOpen != true)
                {
                    serialPort4.Close();
                    InitSingleCom(serialPort4.PortName);
                }

            }
            if (COM5 == serialPort5.PortName)
            {
                if (serialPort5.IsOpen != true)
                {
                    serialPort5.Close();
                    InitSingleCom(serialPort5.PortName);
                }
            }
            if (COM6 == serialPort6.PortName)
            {
                if (serialPort6.IsOpen != true)
                {
                    serialPort6.Close();
                    InitSingleCom(serialPort6.PortName);
                }
            }
            if (COM7 == serialPort7.PortName)
            {
                if (serialPort7.IsOpen != true)
                {
                    serialPort7.Close();
                    InitSingleCom(serialPort7.PortName);
                }
            }
            if (COM8 == serialPort8.PortName)
            {
                if (serialPort8.IsOpen != true)
                {
                    serialPort5.Close();
                    InitSingleCom(serialPort8.PortName);
                }
            }
        }

        public void CloseReceiveData()
        {
            serialPort1.Dispose();
            serialPort2.Dispose();
            serialPort3.Dispose();
            serialPort4.Dispose();
            serialPort5.Dispose();
            serialPort6.Dispose();
            serialPort7.Dispose();
            serialPort8.Dispose();
            serialPort1.Close();
            serialPort2.Close();
            serialPort3.Close();
            serialPort4.Close();
            serialPort5.Close();
            serialPort6.Close();
            serialPort7.Close();
            serialPort8.Close();

        }
        #endregion

        public void ClearControl()
        {
            barCode_ZWS_L.Invoke(new Action(() => { barCode_ZWS_L.Visible = false; }));
            barCode_ZWS_R.Invoke(new Action(() => { barCode_ZWS_R.Visible = false; }));
            barCode_ZPL_L.Invoke(new Action(() => { barCode_ZPL_L.Visible = false; }));
            barCode_ZPL_R.Invoke(new Action(() => { barCode_ZPL_R.Visible = false; }));
            txtWaitQty.Invoke(new Action(() => { txtProcessType.Text = ""; }));
            txtOrderNo.Invoke(new Action(() => { txtOrderNo.Text = ""; }));
            txtOrderNumber.Invoke(new Action(() => { txtOrderNumber.Text = ""; }));
            txtPartNo.Invoke(new Action(() => { txtPartNo.Text = ""; }));
            txtDwgNo.Invoke(new Action(() => { txtDwgNo.Text = ""; }));
            txtOrderQty.Invoke(new Action(() => { txtOrderQty.Text = ""; }));
            txtBatchQty.Invoke(new Action(() => { txtBatchQty.Text = ""; }));
            txtBatchCount.Invoke(new Action(() => { txtBatchCount.Text = ""; }));
            txtWaitQty.Invoke(new Action(() => { txtWaitQty.Text = ""; }));
            PL_TempCount = 0;
            YL_TempCount = 0;
            PL_Count = 0;
        }
        private void frmNC_PN_AL_Scan_for_Processing_Resize(object sender, EventArgs e)
        {
            panelControl3.Width = panelControl2.Width;

            groupControl1.Width = panelControl2.Width;//基本信息
            groupControl2.Width = panelControl1.Width / 4;//订单信息
            groupControl3.Width = panelControl1.Width / 4;//当前加工

            groupControl5.Height = panelControl2.Height / 2;
            groupControl6.Height = panelControl2.Height / 2;
            groupControl7.Height = panelControl2.Height / 2;
            groupControl8.Height = panelControl2.Height / 2;
        }

        private void frmNC_PN_AL_Scan_for_Processing_FormClosed(object sender, FormClosedEventArgs e)
        {
            CloseReceiveData();
        }

        //特殊用户专用功能
        private void txtOrderNumber_KeyPress(object sender, KeyPressEventArgs e)
        {
            try
            {
            string strBarcode = txtOrderNumber.Text.Trim();
            if (strBarcode.Length <= 0) return;
            if (IsExistNCProgram(strBarcode))
            {
                ClearControl();
                PL_TempCount = Common.GetSerialNumber.GetSerialNo(strBarcode);
                YL_TempCount = Common.GetSerialNumber.GetSerialNo_YL(strBarcode);
                //订单信息
                GetOrderInfo(strBarcode);
                //计算待加工数量
                txtWaitProcessQty.Invoke(new Action(() =>
                {
                    txtWaitProcessQty.Text = Common.SQLHelper.GetScanQty(txtOrderNumber.Text.Trim() + "_" + txtPartNo.Text.Trim(), Convert.ToInt32(txtOrderQty.Text.Trim())).ToString();
                }));
                //当待加工数量为0时，不显示余量二维码
                if (txtWaitProcessQty.Text.Trim() == "0")
                    ShowNotQRCode();
                //当天产量
                GetOutPutInfo();
            }
            else
            {
                DevExpress.XtraEditors.XtraMessageBox.Show("此订单尚未出NC程序，请预转码后再扫描！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            }
            catch (Exception ex)
            {
            }
        }
    }
}